package insight.google.game.era.bo.policy.character;

import insight.google.game.era.bo.GameRoom;
import insight.google.game.era.bo.GameUser;
import insight.google.game.era.bo.card.GameCard;
import insight.google.game.era.client.proxy.PlayerClientProxy;
import insight.google.game.era.client.proxy.PlayerClientProxyImpl;
import insight.google.game.era.core.Util;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class SunQuanPolicy extends CharacterPolicy {

    /**
	 * 
	 */
	private PlayerClientProxy playerClientProxy;

    public SunQuanPolicy(String id, String name){
		super(id, name);
	}

	@Override
	public boolean beHurtedExec(GameUser original, GameUser[] targets,
			Map params) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean beSelectedExec(GameUser original, GameUser[] targets,
			Map params) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean onDiscardExec(GameUser original, GameUser[] targets,
			Map params) {
		// TODO Auto-generated method stub
        playerClientProxy = PlayerClientProxyImpl.getInstance();

		String jsComponentId = (String)params.get("jsComponenetId");

		//set target user active card
        List<String> activeCards = new ArrayList<String>();
        activeCards.add("base");
        activeCards.add("arm");
//        original.setActiveCards(activeCards);
//        playerClientProxy.setActiveCard(original.getScriptProxy(), jsComponenetId, original.getActiveCards());
//        playerClientProxy.enablePolicyExec(original.getScriptProxy(), jsComponenetId, original);
        original.setActiveCards(activeCards,jsComponentId);
        original.enablePolicyExecute(jsComponentId);
		return true;
	}

	@Override
	public boolean onTurnExec(GameUser original, GameUser[] targets, Map params) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean withDiscardExec(GameUser original, GameUser[] targets,
			Map params) {
		// TODO Auto-generated method stub
		String jsComponentId = (String)params.get("jsComponenetId");
		String[] cards = (String[])params.get("cardList");

		GameRoom room = Util.getRoom();

		playerClientProxy = PlayerClientProxyImpl.getInstance();
//        playerClientProxy.setActive(original.getScriptProxy(), jsComponenetId, false);
		original.setClientActive(false, jsComponentId);
        
		int cardCount = cards == null?0:cards.length;

		//remove from user
		for (int i = 0; i < cards.length; i++) {
			GameCard card = room.getCardByCardName(cards[i]);
			original.removeCard(card.getId());
		}
		//clear client selected card.
//        playerClientProxy.removeClientSelectedCard(original.getScriptProxy(), jsComponentId);
		original.removeClientSelectedCards(jsComponentId);

		//send card to target user
        room.sendCardToUserByCount(original, cardCount);
//        for(int i=0; i<targets.length; i++){
//            GameUser tagUser = targets[i];
//            room.sendCardToUserByCount(tagUser, cardCount);
//        }
		//change cards.

        List<String> activeCards = new ArrayList<String>();
        activeCards.add("attack");
        activeCards.add("arm");
//        original.setActiveCards(activeCards);
        original.setActiveCards(activeCards,jsComponentId);
        original.setClientActive(true, jsComponentId);
//        playerClientProxy.setActiveCard(original.getScriptProxy(), jsComponentId, original.getActiveCards());
//
//        playerClientProxy.setActive(original.getScriptProxy(), jsComponentId, true);
        
        return true;
	}

}
